package 蓝桥真题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class 路径之谜 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       final static int N=21;
       static boolean g[][]=new boolean[N][N];
       static int nba[]=new int[N],wba[]=new int[N],tnba[]=new int[N],twba[]=new int[N],path[]=new int[N*N],n,cnt;
       static int dix[]={-1,1,0,0},diy[]={0,0,-1,1};
       static boolean st[][]=new boolean[N][N];
       static void dfs(int x,int y){
    	      if(x==n-1&&y==n-1){
    	    	  boolean flag=true;
    	    	  for(int i=0;i<n;i++)
    	    		  if(nba[i]!=tnba[i]){
    	    			  flag=false;
    	    			  break;
    	    		  }
    	    	  for(int i=0;i<n;i++)
    	    		  if(flag&&wba[i]!=twba[i]){
    	    			  flag=false;
    	    			  break;
    	    		  }
    	    	  if(flag){
    	    		  for(int i=0;i<cnt;i++)
    	    			  System.out.print(path[i]+" ");
    	    		  System.exit(0);
    	    	  }
    	    	  return;
    	      }
    	      for(int i=0;i<4;i++){
    	    	  int a=dix[i]+x,b=diy[i]+y;
    	    	  if(a>=0&&a<n&&b>=0&&b<n&&!st[a][b]&&tnba[b]<nba[b]&&twba[a]<wba[a]){
    	    		  tnba[b]++;twba[a]++;
    	    		  path[cnt++]=a*n+b;
    	    		  st[a][b]=true;
    	    		  dfs(a,b);
    	    		  tnba[b]--;twba[a]--;
    	    		  cnt--;
    	    		  st[a][b]=false;
    	    	  }
    	      }
    	      
       }
       public static void main(String[] ss) throws NumberFormatException, IOException {
		      n=Integer.parseInt(br.readLine());
		      ss=br.readLine().split(" ");
		      for(int i=0;i<n;i++)
		    	  nba[i]=Integer.parseInt(ss[i]);
		      ss=br.readLine().split(" ");
		      for(int i=0;i<n;i++)
		    	  wba[i]=Integer.parseInt(ss[i]);
		      tnba[0]++;twba[0]++;
    		  path[cnt++]=0;
    		  st[0][0]=true;
		      dfs(0,0);
	}
}
